/*   1:    */ package org.intellij.plugins.relaxNG.model.annotation;
/*   2:    */ 
/*   3:    */

import com.intellij.lang.annotation.Annotation;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.Annotator;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.editor.markup.GutterIconRenderer;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.PsiElementProcessor.FindElement;
import com.intellij.psi.xml.XmlFile;
import com.intellij.util.SmartList;
import com.intellij.util.xml.DomElement;
import com.intellij.util.xml.highlighting.DomElementAnnotationHolder;
import com.intellij.util.xml.highlighting.DomElementsAnnotator;
import org.intellij.plugins.relaxNG.model.CommonElement;
import org.intellij.plugins.relaxNG.model.Define;
import org.intellij.plugins.relaxNG.model.Grammar;
import org.intellij.plugins.relaxNG.model.Include;
import org.intellij.plugins.relaxNG.model.resolve.DefinitionResolver;
import org.intellij.plugins.relaxNG.model.resolve.GrammarFactory;
import org.intellij.plugins.relaxNG.model.resolve.RelaxIncludeIndex;
import org.intellij.plugins.relaxNG.xml.dom.RngDomElement;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Set;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */ 
/*  30:    */ public final class ModelAnnotator
/*  31:    */   implements Annotator, DomElementsAnnotator
/*  32:    */ {
/*  33:    */   public void annotate(@NotNull PsiElement paramPsiElement, @NotNull AnnotationHolder paramAnnotationHolder)
/*  34:    */   {
/*  35: 54 */     if (paramPsiElement == null) {
/*  36: 54 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/model/annotation/ModelAnnotator", "annotate" }));
/*  37:    */     }
/*  38: 54 */     if (paramAnnotationHolder == null) {
/*  39: 54 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/intellij/plugins/relaxNG/model/annotation/ModelAnnotator", "annotate" }));
/*  40:    */     }
/*  41: 54 */     if ((paramPsiElement instanceof CommonElement)) {
/*  42: 55 */       ((CommonElement)paramPsiElement).accept(new MyAnnotator(CommonAnnotationHolder.create(paramAnnotationHolder)));
/*  43:    */     }
/*  44:    */   }
/*  45:    */   
/*  46:    */   public void annotate(DomElement paramDomElement, DomElementAnnotationHolder paramDomElementAnnotationHolder)
/*  47:    */   {
/*  48: 60 */     if ((paramDomElement instanceof RngDomElement)) {
/*  49: 61 */       ((RngDomElement)paramDomElement).accept(new MyAnnotator(CommonAnnotationHolder.create(paramDomElementAnnotationHolder)));
/*  50:    */     }
/*  51:    */   }
/*  52:    */   
/*  53:    */   private final class MyAnnotator<T>
/*  54:    */     extends CommonElement.Visitor
/*  55:    */   {
/*  56:    */     private final CommonAnnotationHolder<T> a;
/*  57:    */     
/*  58:    */     public MyAnnotator()
/*  59:    */     {
/*  60:    */       Object localObject;
/*  61: 69 */       this.a = localObject;
/*  62:    */     }
/*  63:    */     
/*  64:    */     public void visitDefine(Define paramDefine)
/*  65:    */     {
/*  66: 73 */       PsiElement localPsiElement = paramDefine.getPsiElement();
/*  67: 74 */       if (localPsiElement != null)
/*  68:    */       {
/*  69: 75 */         XmlFile localXmlFile = (XmlFile)localPsiElement.getContainingFile();
/*  70:    */         
/*  71: 77 */         final SmartList localSmartList = new SmartList();
/*  72: 78 */         final OverriddenDefineSearcher localOverriddenDefineSearcher = new OverriddenDefineSearcher(paramDefine, localXmlFile, localSmartList);
/*  73:    */         
/*  74: 80 */         PsiElementProcessor.FindElement local1 = new PsiElementProcessor.FindElement()
/*  75:    */         {
/*  76:    */           public boolean execute(@NotNull XmlFile paramAnonymousXmlFile)
/*  77:    */           {
/*  78: 82 */             if (paramAnonymousXmlFile == null) {
/*  79: 82 */               throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/model/annotation/ModelAnnotator$MyAnnotator$1", "execute" }));
/*  80:    */             }
/*  81: 82 */             Grammar localGrammar = GrammarFactory.getGrammar(paramAnonymousXmlFile);
/*  82: 83 */             if (localGrammar == null) {
/*  83: 83 */               return true;
/*  84:    */             }
/*  85: 85 */             localGrammar.acceptChildren(localOverriddenDefineSearcher);
/*  86:    */             
/*  87: 87 */             return (localSmartList.size() == 0) || (super.execute(paramAnonymousXmlFile));
/*  88:    */           }
/*  89: 90 */         };
/*  90: 91 */         RelaxIncludeIndex.processBackwardDependencies(localXmlFile, local1);
/*  91: 93 */         if (local1.isFound()) {
/*  92: 94 */           a(paramDefine, new OverriddenDefineRenderer(paramDefine));
/*  93:    */         }
/*  94:    */       }
/*  95:    */     }
/*  96:    */     
/*  97:    */     private void a(CommonElement paramCommonElement, GutterIconRenderer paramGutterIconRenderer)
/*  98:    */     {
/*  99:101 */       Annotation localAnnotation = this.a.createAnnotation(paramCommonElement, HighlightSeverity.INFORMATION, null);
/* 100:102 */       localAnnotation.setGutterIconRenderer(paramGutterIconRenderer);
/* 101:    */     }
/* 102:    */     
/* 103:    */     public void visitInclude(Include paramInclude)
/* 104:    */     {
/* 105:106 */       Define[] arrayOfDefine1 = paramInclude.getOverrides();
/* 106:107 */       for (Define localDefine : arrayOfDefine1)
/* 107:    */       {
/* 108:108 */         PsiFile localPsiFile = paramInclude.getInclude();
/* 109:109 */         if ((localPsiFile instanceof XmlFile))
/* 110:    */         {
/* 111:111 */           Grammar localGrammar = GrammarFactory.getGrammar((XmlFile)localPsiFile);
/* 112:112 */           if (localGrammar != null)
/* 113:    */           {
/* 114:114 */             Map localMap = DefinitionResolver.getAllVariants(localGrammar);
/* 115:115 */             if (localMap != null)
/* 116:    */             {
/* 117:117 */               Set localSet = (Set)localMap.get(localDefine.getName());
/* 118:118 */               if ((localSet == null) || (localSet.size() == 0))
/* 119:    */               {
/* 120:120 */                 this.a.createAnnotation(localDefine, HighlightSeverity.ERROR, "Definition doesn't override anything from " + localPsiFile.getName());
/* 121:    */               }
/* 122:    */               else
/* 123:    */               {
/* 124:124 */                 String str = "Overrides '" + localDefine.getName() + "' in " + localPsiFile.getName();
/* 125:125 */                 a(localDefine, new OverridingDefineRenderer(str, localSet));
/* 126:    */               }
/* 127:    */             }
/* 128:    */           }
/* 129:    */         }
/* 130:    */       }
/* 131:    */     }
/* 132:    */   }
/* 133:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.model.annotation.ModelAnnotator

 * JD-Core Version:    0.7.0.1

 */